package com.etc.controller;

import com.etc.entity.CommentResult;
import com.etc.entity.Room;
import com.etc.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RoomController {
    @Autowired
    private RoomService roomService;
    @RequestMapping("room/update")
    public CommentResult update(@RequestBody Room room){
        int result = roomService.update(room);
        if (result>0)
            return new CommentResult(200,"success!");
        else {
            return new CommentResult(444, "failed!");
        }
    }

    @RequestMapping("room/buyRoom/{owner_id}/{id}")
    public CommentResult buyRoom(@PathVariable("owner_id")Integer owner_id, @PathVariable("id")Integer id)
    {
        int result = roomService.buyRoom(owner_id,id);
        if (result>0)
            return new CommentResult(200,"success!");
        else {
            return new CommentResult(444, "failed!");
        }
    }

    @RequestMapping("room/sellRoom/{id}")
    public CommentResult sellRoom(@PathVariable("id")Integer id)
    {
        int result = roomService.sellRoom(id);
        if (result>0)
            return new CommentResult(200,"success!");
        else {
            return new CommentResult(444, "failed!");
        }
    }


}
